#pragma GCC optimize(2)

#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>


using namespace std;
using LL = __int128_t;
using PLL = pair<LL, LL>;
const int mod = 998244353;

LL n, m;
LL a, b, c, d;
int q;

inline __int128 read(){
    __int128 x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
inline void print(__int128 x){
    if(x < 0){
        putchar('-');
        x = -x;
    }
    if(x > 9)
        print(x / 10);
    putchar(x % 10 + '0');
}


PLL k1(LL a, LL b, LL c, LL d){
    LL fo, ed;
    if(a % 2 == 1){
        if(c % 2 == 1){
            fo = ((a - 1) * m % mod + c + 1) % mod;
        }else{
            fo = ((a - 1) * m % mod + c) % mod;
        }

        if(d % 2 == 1){
            ed = ((a - 1) * m % mod + d - 1) % mod;
        }else{
            ed = ((a - 1) * m + d) % mod;
        }
    }else{
        if(c % 2 == 1){
            fo = ((a - 1) * m % mod + c) % mod;
        }else{
            fo = ((a - 1) * m % mod + c + 1) % mod;
        }

        if(d % 2 == 1){
            ed = ((a - 1) * m % mod + d) % mod;
        }else{
            ed = ((a - 1) * m % mod + d - 1) % mod;
        }
    }
    
    LL num = ((ed - fo) / 2 + 1) % mod;
    // LL res = ((fo + ed) / 2 % mod) * num % mod ;  可能会丢失精度
    LL res = fo * num % mod + num * (num - 1) / 2 * 2 % mod;
  //  cout << "fo: " << fo << " ed: " << ed << " num: " << num << endl;
    return {res, num};
}

void solve(LL a, LL b, LL c, LL d){
    LL cfo = ((LL)(a - 1) % mod * m % mod + (LL)c) % mod;
    LL csum = cfo * (d - c + 1) % mod + (d - c + 1) * (d - c) / 2 % mod;
  //  cout << "cfo: " << cfo  << " csum: " << csum << endl;
    LL cd1 = (LL)(d - c + 1) * m % mod;
    LL allsum = (b - a + 1) * csum % mod + (b - a + 1) * (b - a) / 2 % mod * cd1 % mod ;
  //  cout << "allsum: " << allsum << endl;
    
    LL k1sum; 
    LL k2sum; 

    if(a < b){
        PLL t1 = k1(a, b, c, d);
        LL kk1 = t1.first;
        LL enu1 = t1.second;
        LL num1 = (b - a) / 2 + 1;
        LL d1 = enu1 * m * 2 % mod;
        k1sum = (kk1 * num1 % mod + (num1 * (num1 - 1) / 2 % mod)  * d1 % mod) % mod;
    //    cout << "kk1: " << kk1 << " num1: " << num1 <<" d1: " << d1 << " k1sum: " << k1sum << endl;

        PLL t2 = k1(a + 1, b, c, d);
        LL kk2 = t2.first;
        LL enu2 = t2.second;
        LL num2 = (b - a - 1) / 2 + 1;
        LL d2 = enu2 * m * 2 % mod;
        k2sum = (kk2 * num2 % mod + (num2 * (num2 - 1) / 2 % mod) * d2 % mod) % mod;

      //  cout << "kk2: " << kk2 << " num2: " << num2 << " d2: " << d2 << " k2sum: " << k2sum << endl; 
    }else{
        PLL t1 = k1(a, b, c, d);
        LL kk1 = t1.first;
        LL enu = t1.second;
        LL num1 = (b - a) / 2 + 1;
        LL d1 = enu * m * 2 % mod;
        k1sum = (kk1 * num1 % mod + (num1 * (num1 - 1) / 2 % mod) * d1 % mod) % mod;
    //    cout << "kk1: " << kk1 << " k1sum: " << k1sum << endl;
        
        k2sum = 0;
    //    cout << " kk2: " << 0 << " k2sum: " << k2sum << endl;
    }



    LL res = ((allsum - k1sum - k2sum) % mod + mod) % mod;
    printf("%lld\n", res);
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    n = read(), m = read();
    scanf("%d", &q);

    while(q--){
        a = read(), b = read(), c = read(), d = read();
        solve(a, b, c, d);
    }

    return 0;
}